import 'dart:async';
import 'package:demo/event/event_setting.dart';
import 'package:demo/tools/tools_enum.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:demo/views/base/base_controller.dart';

class FriendSettingController extends BaseController {
  // 删除好友
  Future<void> delFriend() async {
    // 通知
    EventSetting().handle(
      SettingModel(
        SettingType.friend,
        primary: refreshData.userId,
        label: 'delete',
      ),
    );
    // 提醒
    EasyLoading.showToast('删除成功');
    // 返回
    Get.back();
  }

  // 好友拉黑
  Future<void> setBlack(String black) async {
    // 设置
    refreshData.black = black;
    update();
    // 通知
    EventSetting().handle(
      SettingModel(
        SettingType.friend,
        primary: refreshData.userId,
        label: 'black',
        value: black,
      ),
    );
  }

  // 好友置顶
  Future<void> setTop(String top) async {
    // 设置
    refreshData.top = top;
    update();
    // 通知
    EventSetting().handle(
      SettingModel(
        SettingType.friend,
        primary: refreshData.userId,
        label: 'top',
        value: top,
      ),
    );
  }

  // 好友静默
  Future<void> setDisturb(String disturb) async {
    // 设置
    refreshData.disturb = disturb;
    update();
    // 通知
    EventSetting().handle(
      SettingModel(
        SettingType.friend,
        primary: refreshData.userId,
        label: 'disturb',
        value: disturb,
      ),
    );
  }

  @override
  void onInit() {
    super.onInit();
    refreshData = Get.arguments;
  }
}
